package 笔试.A网易;

import java.util.Scanner;

public class Main {
    public static void main(String arg[]){//main--来自高金磊

         Scanner scanner=new Scanner(System.in);
         int n=scanner.nextInt();
         int m=scanner.nextInt();

         int data1[][]=new int[n][m];
         int data[][]=new int[n+2][m+2];
         int middle[][]=new int[n+2][m+2];
        for (int i = 0; i < data1.length; i++) {
            for (int j = 0; j < data1[0].length; j++) {
                middle[i+1][j+1]=n*m;
                data[i][j]=data1[i][j];
            }
        }
        middle[1][1]=0;
        for (int i = 1; i <middle.length-1 ; i++) {
            for (int j = 1; j < middle[0].length-1; j++) {
                int re=middle[i][j];
                if (data[i][j]==data[i-1][j]){
                    re=Math.min(re,middle[i-1][j]+1);
                }else {
                    re=Math.min(re,middle[i-1][j]+2);
                }
                if (data[i][j]==data[i-1][j]){
                    re=Math.min(re,middle[i-1][j]+1);
                }else {
                    re=Math.min(re,middle[i-1][j]+2);
                }
                if (data[i][j]==data[i-1][j]){
                    re=Math.min(re,middle[i-1][j]+1);
                }else {
                    re=Math.min(re,middle[i-1][j]+2);
                }
                if (data[i][j]==data[i-1][j]){
                    re=Math.min(re,middle[i-1][j]+1);
                }else {
                    re=Math.min(re,middle[i-1][j]+2);
                }
                middle[i][j]=re;
            }

        }
    }
}
